package pearson.automation.api;

import java.util.ArrayList;
import java.util.HashMap;

import org.w3c.dom.Document;

/**
 * Search assets API.
 */
public class SearchAPI extends BaseAPICall {

    /**
     * Return search results.
     * @param query
     *      Query
     * @param contentType
     *      Limit results to this content type
     * @param results
     *      Number of results
     * @param page
     *      Show results from this page
     * @return a list of asset IDs
     */
    public final ArrayList<String> simpleSearch(
            final String query,
            final String contentType,
            final String results,
            final String page) {
    info(String.format(
                "simpleSearch(%1$s, %2$s, %3$s, %4$s)",
                    query, contentType, results, page));
        String urlTemplate = "rel/api/search";
        HashMap<String, String> parameters = new HashMap<String, String>();
        parameters.put("query", query);
        parameters.put("content_type", contentType);
        parameters.put("results", results);
        parameters.put("page", page);
        Document doc = performAPICall(urlTemplate, parameters, false);
        return getAPICallResults(doc, "search_item", "id");
    }


    @Override
    protected final String formatLogMsg(final String message) {
        return String.format("SearchAPI: %s", message);
    }
}
